﻿using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HinduShop.Domain.Models;

namespace HinduShop.UI.ViewModels.StoreManager
{
    public class EditProductViewModel
    {
        public EditProductViewModel()
        {
        }

        public EditProductViewModel(IEnumerable<Category> categoryList)
        {
            IList<string> categoryNameList = categoryList.Select(category => category.Name).ToList();

            CategorySelectList = new SelectList(categoryNameList);
        }

        public EditProductViewModel(Product product, IEnumerable<Category> categoryList = null)
        {
            // Automapper
            ProductId = product.Id;
            ProductName = product.Name;

            if (product.Category != null)
                CategoryName = product.Category.Name;

            ProductPrice = product.Price;
            HasImage = product.ImageData != null;

            if (categoryList != null)
            {
                IList<string> categoryNameList = categoryList.Select(category => category.Name).ToList();

                CategorySelectList = new SelectList(categoryNameList, CategoryName);
            }
        }

        public int ProductId { get; set; }
        public decimal ProductPrice { get; set; }
        public string ProductName { get; set; }
        public string CategoryName { get; set; }
        public HttpPostedFileBase Image { get; set; }
        public bool HasImage { get; set; }

        public SelectList CategorySelectList { get; set; } 
    }
}